import tkinter as tk

window = tk.Tk()

# .设置窗口属性
window.title("我的第一个Tkinter窗口")  # .窗口标题
window.geometry("500x500")  # .窗口尺寸

# .创建标签
label = tk.Label(window, text="你好，Tkinter！")  # .标签文本
label.pack()  # .将标签添加到窗口

# .创建输入框
text_var = tk.StringVar()
entry = tk.Entry(window, textvariable=text_var)
entry.pack()


def print_text():
    print(text_var.get())


# .创建按钮
button1 = tk.Button(window, text="点击我", command=print_text)  # .按钮文本
button1.pack()  # .将按钮添加到窗口

# .创建文本框
text_box = tk.Text(window, height=5, width=30)
text_box.pack()


def print_text_box():
    print(text_box.get("1.0", "end"))


# .创建按钮
button2 = tk.Button(window, text="输出文本框内容", command=print_text_box)
button2.pack()

# .创建单选按钮
var = tk.StringVar()
var.set("option1")
radio1 = tk.Radiobutton(window, text="选项 1", variable=var, value="option1")
radio1.pack()
radio2 = tk.Radiobutton(window, text="选项 2", variable=var, value="option2")
radio2.pack()


def print_selected():
    print("已选选项:", var.get())


button3 = tk.Button(window, text="输出选项", command=print_selected)
button3.pack()

window.mainloop()
